package com.songcha.sakura.ui.decoration

import android.graphics.Rect
import android.view.View
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.StaggeredGridLayoutManager
import com.songcha.library_common.util.dp2px


class HomeComicItemDecoration() : RecyclerView.ItemDecoration() {
    override fun getItemOffsets(
        outRect: Rect,
        view: View,
        parent: RecyclerView,
        state: RecyclerView.State
    ) {
        //super.getItemOffsets(outRect, view, parent, state)

        val layoutParams: StaggeredGridLayoutManager.LayoutParams =
            view.layoutParams as StaggeredGridLayoutManager.LayoutParams
        //item交换的时候会出bug

        if(layoutParams.spanIndex%2==0){
            outRect.left=10.dp2px()
            outRect.top=2.5f.dp2px().toInt()
            outRect.bottom=2.5f.dp2px().toInt()
        }else{
            outRect.left=5.dp2px()
            outRect.right=5.dp2px()
            outRect.top=2.5f.dp2px().toInt()
            outRect.bottom=2.5f.dp2px().toInt()
        }

    }
}